//
//  ViewController.m
//  15-HomeWork
//
//  Created by dllo on 16/8/3.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ViewController.h"
#import "LabelCollectionViewCell.h"
#import "LabelFlowLayout.h"
#import "SelfSizeText.h"
@interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, waterFlowLayoutDelegate>
@property (nonatomic, strong)NSArray *arr;
@property (nonatomic, strong)UICollectionView *collection;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"网易";
    self.navigationController.navigationBar.translucent = NO;
    // scrollView自动边距
    // 遇到状态栏, 导航栏, 自动为页面上的某一个ScrollView添加边距
    // 一般在开发中, 关闭这个属性
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self creatcollectionView];
    [self creatLabel];
}
- (void)creatcollectionView {
    
    LabelFlowLayout *layout = [[LabelFlowLayout alloc] init];
    layout.delegate = self;
    
    _collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width , 60) collectionViewLayout:layout];
    _collection.backgroundColor = [UIColor whiteColor];
    
    _collection.delegate = self;
    _collection.dataSource = self;
    [self.view addSubview:_collection];
    [_collection registerClass:[LabelCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    }
- (void)creatLabel {
    NSArray *array = @[@"头条", @"精选", @"娱乐", @"体育", @"网易号", @"北京", @"视频", @"财经", @"科技", @"汽车", @"时尚", @"图片", @"直播", @"热点", @"跟帖", @"房产", @"轻松一刻", @"段子", @"军事"];
    _arr = [NSMutableArray arrayWithArray:array];
//    for (int i = 0; i < 19; i++) {
//        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * self.view.bounds.size.width / 6 , 0 , self.view.bounds.size.width / 6 , 50 )];
//        titleLabel.textColor = [UIColor blackColor];
//        titleLabel.textAlignment = 1;
//        titleLabel.text = _arr[i];
//        [_collection addSubview:titleLabel];
    //}

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _arr.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LabelCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.label.text = _arr[indexPath.row];
    NSLog(@"%@", cell.label.text);
   return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout height:(CGFloat)height heightForItemAtIndexPath:(NSIndexPath *)indexPath {
    NSString *str = [_arr objectAtIndex:indexPath.row];
    return [SelfSizeText selfSizeWidthWithString:str height:60 font:[UIFont systemFontOfSize:17]];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
